package forth_exp;
import java.util.ArrayList;

public class TrunkMain {
    public static void main(String[] args) {
        Television tv = new Television();
        Computer cp = new Computer();
        WashMachine wm = new WashMachine();

        Trunk trunk = new Trunk();
        trunk.addObj(tv);
        trunk.addObj(cp);
        trunk.addObj(wm);

        System.out.println(trunk.getTotalWeight());
    }
}

interface ComputeWeight {
    public double computeWeight();
}

class Television implements ComputeWeight {
    public double computeWeight() {
        return 20;
    }
}

class Computer implements ComputeWeight {
    public double computeWeight() {
        return 10;
    }
}

class WashMachine implements ComputeWeight {
    public double computeWeight() {
        return 30;
    }
}

class Trunk {
    private ArrayList<ComputeWeight> trunks;

    public Trunk() {
        trunks = new ArrayList<>();
    }

    public double getTotalWeight() {
        double totalWeight = 0;
        for (ComputeWeight trunk : trunks) {
            totalWeight += trunk.computeWeight();
        }
        return totalWeight;
    }

    public void addObj(ComputeWeight obj) {
        trunks.add(obj);
    }
}